package org.dev.vlp.controller;

import org.dev.vlp.bean.JsonResponse;
import org.dev.vlp.constants.Roles;
import org.dev.vlp.dto.PublishCommentParam;
import org.dev.vlp.dto.PublishMomentParam;
import org.dev.vlp.interceptor.RequiredPermission;
import org.dev.vlp.service.CommentService;
import org.dev.vlp.service.MomentService;
import org.dev.vlp.utils.PageResult;
import org.dev.vlp.vo.MomentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Description
 * Param
 * return
 * Author:86184
 * Date: 2023/1/14
 */
@RestController
@RequestMapping("/comment")
@RequiredPermission({Roles.ROLE_USER})
public class CommentController extends BaseController {

    @Autowired
    private CommentService commentService;


    @PutMapping
    public JsonResponse<Object> publishComment(@Valid @RequestBody PublishCommentParam commentParam) {
        commentService.publishComment(commentParam,(int)getUid());
        return JsonResponse.success();
    }

    @DeleteMapping({"/{commentId}"})
    public JsonResponse<Object> deleteComment(@PathVariable("commentId") int commentId) {

        commentService.deleteComment(commentId,(int)getUid());
        return JsonResponse.success();
    }

    @PostMapping
    public JsonResponse<PageResult> queryMomentComment(@RequestParam int momentId,
                                                   @RequestParam int parentId,
                                                   @RequestParam int page,
                                                   @RequestParam int size) {

        PageResult pageResult = commentService.queryMomentComment((long) momentId, page, size, (int) getUid(), parentId);
        return JsonResponse.success(pageResult);
    }
}
